package com.docmgmt.mvp.controller;

import com.docmgmt.mvp.dto.Result;
import com.docmgmt.mvp.ragflow.RAGFlowClient;
import com.docmgmt.mvp.ragflow.dto.EmbeddingModelVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RAGFlow 模型管理 Controller
 * 
 * 提供 LLM 模型、Embedding 模型等查询接口
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/ragflow/models")
@RequiredArgsConstructor
@Tag(name = "RAGFlow 模型管理", description = "RAGFlow LLM 和 Embedding 模型管理接口")
public class RAGFlowModelController {

    private final RAGFlowClient ragFlowClient;

    /**
     * 获取所有可用的 Embedding 模型列表
     *
     * GET /api/v1/ragflow/models/embedding
     *
     * @return Embedding 模型列表
     */
    @GetMapping("/embedding")
    @PreAuthorize("hasAuthority('ragflow:kb:read')")
    @Operation(summary = "获取 Embedding 模型列表", description = "获取所有可用的 Embedding 模型，用于知识库配置")
    public Result<List<EmbeddingModelVO>> listEmbeddingModels() {
        try {
            log.info("收到获取 Embedding 模型列表请求");
            List<EmbeddingModelVO> models = ragFlowClient.listEmbeddingModels();
            log.info("成功返回 {} 个 Embedding 模型", models.size());
            return Result.success(models);
        } catch (Exception e) {
            log.error("获取 Embedding 模型列表失败", e);
            return Result.error("获取 Embedding 模型列表失败: " + e.getMessage());
        }
    }
}

